namespace CSharpPro._1027;

public class Demo_5
{
    public class User
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }

    public interface UserService
    {
        bool AddUser(User user);
        bool DeleteUser(int userId);
        bool UpdateUser(User user);
        User GetUserById(int userId);
    }

    public class UserServiceImpl : UserService
    {
        public bool AddUser(User user)
        {
            if (user == null)
                return false;
        
            Console.WriteLine($"用户 {user.Name} (ID: {user.Id}) 添加成功");
            return true;
        }

        public bool DeleteUser(int userId)
        {
            if (userId <= 0)
                return false;
        
            Console.WriteLine($"ID为 {userId} 的用户删除成功");
            return true;
        }

        public bool UpdateUser(User user)
        {
            if (user == null || user.Id <= 0)
                return false;
        
            Console.WriteLine($"用户 {user.Name} (ID: {user.Id}) 信息更新成功");
            return true;
        }

        public User GetUserById(int userId)
        {
            if (userId <= 0)
                return null;
        
            Console.WriteLine($"查询到ID为 {userId} 的用户");
            return new User { Id = userId, Name = "测试用户" };
        }
    }

    public static class Program
    {
        static void Main()
        {
            UserService userService = new UserServiceImpl();
        
            userService.AddUser(new User { Id = 1, Name = "张三" });
        
            User user = userService.GetUserById(1);
        
            if (user != null)
            {
                user.Name = "张三三";
                userService.UpdateUser(user);
            }
        
            userService.DeleteUser(1);
        }
    }
}